<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="/js/axios.min.js">
    </script>
    <script>
        function checkUserName() {
            //向服务器发送ajax的get请求，第一个参数为URL路径，第二个参数为请求数据
            axios.get("/user/checkName", {
                params: {
                    userName: $("name").value
                }
            }).then(resp => {
                var str = resp.data;
                if (str == "ok") {
                    $("nameSpan").innerHTML = "该用户存在";
                    $("nameSpan").style.color = "red";
                } else {
                    $("nameSpan").innerHTML = "可以使用";
                    $("nameSpan").style.color = "green";
                }
            })
        }

        function $(id) {
            return document.getElementById(id)
        }

        window.onload = function () {
            showData()
        }

        function showData() {
            axios.get("/user//getList").then(resp => {
                var info = resp.data;
                let str = "";
                info.forEach(n => {
                    str += `<tr><td>${n.id}</td><td>${n.name}</td><td>${n.birthday}</td></tr>`
                })
                $("data").innerHTML = str;
            })
        }

    </script>
</head>
<body>
用户名:<input type="text" id="name" onblur="checkUserName()"><br>
<span id="nameSpan"></span><br>
电话:<input type="text" id="phone"><br>

<table border="1" width="60%" cellspacing="0">
    <thead>
    <tr>
        <th>编号</th>
        <th>姓名</th>
        <th>生日</th>
    </tr>
    </thead>
    <tbody id="data">

    </tbody>
</table>
</body>
</html>